﻿Imports PTCON

Public Class SystemDatabase
    Dim conn As IConnect
    Dim strConnSelected As String

    Public Function getListDBName() As DataTable

        Dim dt As DataTable
        conn = New SQLServConnect()
        conn.connect(Config.ConnectString)
        Dim sql = "SELECT * " & _
                  "FROM master.dbo.sysdatabases " & _
                  "WHERE dbid > 4  "
        conn.query(sql)
        dt = conn.dataTable()
        conn.close()
        Return dt

    End Function

    Public Function getListTable(ByVal dbName As String, ByVal schema As String) As DataTable
        Dim dt As DataTable
        Dim conf As New Config()
        conf._DBName = dbName
        strConnSelected = conf.getConnectString()

        conn = New SQLServConnect()

        conn.connect(strConnSelected)

        'Dim sql As String = "SELECT * FROM information_schema.tables " &
        '                    "WHERE TABLE_TYPE = 'BASE TABLE'" &
        '                    "ORDER BY TABLE_NAME"


        Dim sql As String = "SELECT * FROM information_schema. " & schema

        '"ORDER BY TABLE_NAME"

        conn.query(sql)
        dt = conn.dataTable()
        conn.close()
        Return dt
    End Function

    Public Function getFieldTable(ByVal tableName As String) As DataTable
        Dim dt As DataTable
        conn = New SQLServConnect()
        conn.connect(strConnSelected)
        Dim sql As String = "SELECT * FROM information_schema.columns " &
                             "WHERE table_name = '" & tableName & "' "
        conn.query(sql)
        dt = conn.dataTable()
        conn.close()
        Return dt
    End Function
End Class
